package com.controller.admin.company;

import com.dao.AdminDao;
import com.dao.imp.AdminDaoimpl;
import com.entity.Company;
import com.service.AdminService;
import com.service.impl.AdminServiceimpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/AddCompany")
public class AddCompanyServlet  extends HttpServlet {
    AdminService adminService=new AdminServiceimpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

        String companyid = req.getParameter("companyId");
        String companyname = req.getParameter("companyName");
        String companyaddress = req.getParameter("companyAddress");
        String companytel= req.getParameter("companyTel");
        String companyemail = req.getParameter("companyEmail");
        String addtime = req.getParameter("addTime");
        String gongshangnum = req.getParameter("gongNum");
        String state = req.getParameter("state");
//        String name = req.getParameter("name");
        String pwd = req.getParameter("pwd");
        System.out.println("pwd = " + pwd);

        System.out.println("state = " + state);

        Company company = new Company();
        company.setCompanyId(companyid);
        company.setCompanyName(companyname);
        company.setCompanyAddress(companyaddress);
        company.setCompanyTel(companytel);
        company.setCompanyEmail(companyemail);
        company.setAddTime(addtime);
        company.setGongNum(gongshangnum);
        company.setState(state);
        company.setPwd(pwd);
//        company.setCompanyName(name);
        System.out.println("company = " + company);
        int addi = adminService.AddCompany(company);
        System.out.println("addi = " + addi);
        if(addi==1){
            resp.getWriter().write("success");
        }else{
            resp.getWriter().write("fail");
        }
    }
}
